package com.bruce.asurada.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.cors.CorsConfigurationSource;

import jakarta.annotation.Resource;

/**
 * 安全配置 - 禁用Spring Security默认配置
 * 
 * @author Bruce
 */
@Configuration
@EnableWebSecurity
public class SecurityConfig {

    // 注入CORS配置源（替代直接注入CorsFilter）
    @Resource
    private CorsConfigurationSource corsConfigurationSource;

    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http
            // 启用CORS支持，并关联我们的CORS配置
            .cors(cors -> cors.configurationSource(corsConfigurationSource))
            .authorizeHttpRequests(authz -> authz
                .anyRequest().permitAll()  // 允许所有请求
            )
            .csrf(csrf -> csrf.disable())  // 禁用CSRF
            .formLogin(form -> form.disable())  // 禁用默认登录页面
            .httpBasic(basic -> basic.disable());  // 禁用HTTP Basic认证
        
        return http.build();
    }
}
